package com.jing.controller;

import com.jing.common.core.domain.R;
import com.jing.common.core.web.controller.BaseController;
import com.jing.common.core.web.page.TableDataInfo;
import com.jing.common.log.annotation.Log;
import com.jing.common.log.enums.BusinessType;
import com.jing.domain.Vo.ProducAttributetCategoryVO;
import com.jing.domain.Vo.ProductAttributsVO;
import com.jing.domain.Vo.ProductCategoryVO;
import com.jing.domain.po.ProductCategoryPO;
import com.jing.service.ProductCategoryTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author：wp
 * @Package：com.jing.controller
 * @Project：jing
 * @name：ProductCategoryTypeController
 * @Date：2024/5/26 14:19
 */
@RestController
@RequestMapping("productcategorytype")
@Api(tags = "分类下级表")
@Slf4j
public class ProductCategoryTypeController extends BaseController {
    @Autowired
    private ProductCategoryTypeService productCategoryTypeService;
    @Autowired
    private HttpServletRequest request;

    @ApiOperation ( "下级分表" )
    @GetMapping("list")
    public TableDataInfo list(@RequestParam(required = false) Integer pageNum,@RequestParam(required = false) Integer pageSize){
        log.info ( "controller:路经：{}，请求方式：{}，传入参数是{}{},"
                ,request.getRequestURI (),request.getMethod (), pageNum,pageSize);
        startPage ();
         List<ProductAttributsVO> list1= productCategoryTypeService.list(pageNum,pageSize);
        TableDataInfo dataTable = getDataTable ( list1 );
        return dataTable;
    }

    @ApiOperation ("删除")
    @GetMapping("/del/{id}")
    public R del(@PathVariable Integer id){
        log.info ( "controller:路经：{}，请求方式：{}，传入参数是{}{},"
                ,request.getRequestURI (),request.getMethod (), id,null);
        productCategoryTypeService.del(id);
        return R.ok ();
    }

    @ApiOperation ( "图片上传" )
    @PostMapping("img")
    public String mig(@RequestParam("file") MultipartFile file){
        log.info ( "controller:路经：{}，请求方式：{}，传入参数是{}{},"
                ,request.getRequestURI (),request.getMethod (), file,null);
        String img=productCategoryTypeService.img(file);
        return img;
    }

    @ApiOperation ( "品牌分类添加" )
    @PostMapping("add")
    public R productcategoryadd(@RequestBody ProductAttributsVO productAttributsVO ){
        log.info ( "==============参数是{}============",productAttributsVO);
       productCategoryTypeService.add(productAttributsVO);
        return R.ok ();
    }
    @ApiOperation ( "品牌分类修改" )
    @PostMapping("updata")
    public R productcategoryupdate(@RequestBody ProductAttributsVO pms){
        log.info ( "==============参数是{}============",pms);
        productCategoryTypeService.up(pms);
        return R.ok ();
    }
    @GetMapping("ProducAC")
    public R ProducAttributetCategoryPOlist(){
        return R.ok (productCategoryTypeService.pac());
    }

    @GetMapping("chaid/{id}")
    public R   chaid(@PathVariable Integer id){
        return R.ok (productCategoryTypeService.id(id));
    }



}
